/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.config;

import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Project: mybatis2022 - SpringCacheConfig
 * <p>Powered by webrx On 2022-04-15 11:29:17
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@EnableCaching
@Configuration
public class SpringCacheConfig  extends CachingConfigurerSupport {

    @Resource(name = "simpleCacheManager")
    private CacheManager simpleCacheManager;

    @Override
    public CacheManager cacheManager() {
        return simpleCacheManager;
    }

    @Bean
    public SimpleCacheManager simpleCacheManager(List<Cache> cacheList){
        SimpleCacheManager cacheManager = new SimpleCacheManager();
        cacheManager.setCaches(cacheList);
        return cacheManager;
    }

    @Bean
    public ConcurrentMapCacheFactoryBean defaultCacheBean(){
        ConcurrentMapCacheFactoryBean defaultFactoryBean = new ConcurrentMapCacheFactoryBean();
        defaultFactoryBean.setName("default");
        return defaultFactoryBean;
    }

    @Bean
    public ConcurrentMapCacheFactoryBean userCacheBean(){
        ConcurrentMapCacheFactoryBean usersFactoryBean = new ConcurrentMapCacheFactoryBean();
        usersFactoryBean.setName("users");
        return usersFactoryBean;
    }
}
